import 'package:flutter/widgets.dart';
import 'package:get/get.dart';

extension ExWidget on Widget {
  // 使用的时候：
  // Colum().constrained(width:300)
  // 就很方便的给垂直的线性布局约束一个宽度。
  Widget constrained({
    Key? key,
    double? width,
    double? height,
    double minWidth = 0.0,
    double maxWidth = double.infinity,
    double minHeight = 0.0,
    double maxHeight = double.infinity,
  }) {
    BoxConstraints constraints = BoxConstraints(
      minWidth: minWidth,
      maxWidth: maxWidth,
      minHeight: minHeight,
      maxHeight: maxHeight,
    );
    constraints = (width != null || height != null)
        ? constraints.tighten(width: width, height: height)
        : constraints;
    return ConstrainedBox(key: key, constraints: constraints, child: this);
  }

  /// 约束 高度
  Widget height(double height, {Key? key}) {
    return ConstrainedBox(
        constraints: BoxConstraints.tightFor(height: height),
        key: key,
        child: this);
  }

  /// 限制盒子 最大宽高
  Widget limitBox(
      {Key? key,
      double maxWidth = double.infinity,
      double maxHeight = double.infinity}) {
    return limitBox(key: key, maxWidth: maxWidth, maxHeight: maxHeight);
  }

  /// 偏移
  Widget offstage({
    Key? key,
    bool offstage = true,
  }) {
    return Offstage(key: key, offstage: offstage, child: this);
  }

  //内间距
  Widget padding({
    Key? key,
    EdgeInsetsGeometry? value,
    double? all,
    double? horizontal,
    double? vertical,
    double? top,
    double? bottom,
    double? left,
    double? right,
  }) =>
      Padding(
        key: key,
        padding: value ??
            EdgeInsets.only(
                top: top ?? vertical ?? all ?? 0.0,
                bottom: bottom ?? vertical ?? all ?? 0.0,
                left: left ?? horizontal ?? all ?? 0.0,
                right: right ?? horizontal ?? all ?? 0.0),
        child: this,
      );




}
